package com.sz.springboot_jpa.service.impl;

import com.sz.springboot_jpa.entity.Category;
import com.sz.springboot_jpa.repository.CategoryRepository;
import com.sz.springboot_jpa.service.CategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Resource
    private CategoryRepository categoryRepository;

    @Override
    public List<Category> findAll() {

        Iterable<Category> all = categoryRepository.findAll();
        Iterator<Category> ic = all.iterator();
        List<Category> lc = new ArrayList<>();
        while(ic.hasNext()){
            lc.add(ic.next());
        }
        return lc;
    }

    @Override
    public List<Category> findByParent(Integer parent) {
        return categoryRepository.findByParent(parent);
    }
}
